package com.example.musicplayer.activity;


import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Message;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.example.musicplayer.R;
import com.example.musicplayer.utils.GetAllActivity;

public class FirstActivity extends AppCompatActivity {
    private Button btn, btn2;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent = new Intent(FirstActivity.this, LoginActivity.class);    //收到消息后跳转
            startActivity(intent);
            FirstActivity.this.finish();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        verifyPermissions(this);
        handler.sendEmptyMessageDelayed(0, 2000);        //  延迟3秒后发送一个空消息
        btn = (Button) findViewById(R.id.btn_activity_login_login);
        GetAllActivity.getInstance().addActivity(this);
        btn.setOnClickListener(new FirstActivity.btuclock());
    }

    class btuclock implements View.OnClickListener {
        public void onClick(View v) {

            Intent intent = new Intent(FirstActivity.this, LoginActivity.class);
            startActivity(intent);
            FirstActivity.this.finish();
        }
    }


    private static final int REQUEST_EXTERNAL_STORAGE_AND_INTERNET = 1;
    private static String[] PERMISSIONS = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
    };
    public static void verifyPermissions(Activity activity) {
        // Check if we have write permission
        int permission1 = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE);
        if ((permission1 != PackageManager.PERMISSION_GRANTED)) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    activity,
                    PERMISSIONS,
                    REQUEST_EXTERNAL_STORAGE_AND_INTERNET
            );
        }
    }

}